#! /usr/bin/python
# -*- coding:utf-8 -*-

## ========================================================================
## Copyright (C) 2007-2013  Jean-Philippe GOLAY
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
## ========================================================================

from persistance import *


class CustomerCms:


  def __init__(self):
    self.mDB=ManageDB(Glob.dbName, Glob.user, Glob.passwd, Glob.host)
    logging.basicConfig(filename=Glob.LOG_FILENAME,level=logging.DEBUG)


  def getCustomerMenu(self):
    return ""


  def getSalesCustomer(self, id):
    if (self.mDB.executSQL(Glob.select_from_sale_where_user_id % id ) == 0):
      logging.debug(u'CustomerCms: getSalesCustomer SQL request : %s' % Glob.select_from_sale_where_user_id % id )
      return 0
    else:
      result=self.mDB.resultSQL()
      if len( result ) > 0:
        html_list = u""
        for row in result:
          html_list += u"" % (row[1], row[0], row[0])
        return html_list
      else:
        return 0

  
  def getSalesList(self):
    if (self.mDB.executSQL(Glob.select_all_from_sale) == 0):
      logging.debug(u'CustomerCms getSalesList SQL request : %s' % Glob.select_all_from_sale)
      return 0
    else:
      result=self.mDB.resultSQL()
      if len( result ) > 0:
        html_list = u""
        for row in result:
          html_list += u"" % (row[1], row[0], row[0])
        return html_list
      else:
        return 0


  def getPageHeader(self):
    html_header = u"<table border='0' cellspacing='0' cellpadding='0' align='center' width='100%' id='pagesList'>\n"
    return html_header


  def getPageFooter(self):
    html_footer = u"</table>\n"
    return html_footer
